import request from '@/utils/request'

interface ApiResponse<T = any> {
  code: number;
  msg: string;
  data: T;
}

interface PageResult<T> {
  records: T[];
  total: number;
  size: number;
  current: number;
  pages: number;
}

interface DeptItem {
  id?: number;
  parentId?: number;
  name: string;
  orderNum?: number;
  leader?: string;
  phone?: string;
  email?: string;
  status?: number;
  children?: DeptItem[];
}

// 获取部门列表
export function getDeptList() {
  return request({
    url: '/api/dept/list',
    method: 'get'
  })
}

// 获取部门分页列表
export function getDeptPage(params: any) {
  return request({
    url: '/api/dept/page',
    method: 'get',
    params
  })
}

// 获取部门详情
export function getDept(id: number) {
  return request({
    url: `/api/dept/${id}`,
    method: 'get'
  })
}

// 新增部门
export function addDept(data: any) {
  return request({
    url: '/api/dept',
    method: 'post',
    data
  })
}

// 修改部门
export function updateDept(data: any) {
  return request({
    url: '/api/dept',
    method: 'put',
    data
  })
}

// 删除部门
export function deleteDept(id: number) {
  return request({
    url: `/api/dept/${id}`,
    method: 'delete'
  })
}

// 获取部门用户列表
export function getDeptUsers(deptId: number) {
  return request({
    url: `/api/dept/users/${deptId}`,
    method: 'get'
  })
}

// 分配用户到部门
export function assignUsers(deptId: number, userIds: number[]) {
  return request({
    url: '/api/dept/assignUsers',
    method: 'post',
    params: { deptId },
    data: userIds
  })
}

// 从部门移除用户
export function removeUser(deptId: number, userId: number) {
  return request({
    url: '/api/dept/removeUser',
    method: 'delete',
    params: { deptId, userId }
  })
} 